#!/bin/bash

SRC=$1
DST=$2

SRC_DIR=/mnt/src_drive
DST_DIR=/mnt/dst_drive

if [ -z $SRC ] || [ -z $DST ]; then
	echo "Usage: clonehd source-drive destination-drive"
	echo "  e.g. clonehd /dev/sda1 /dev/sdb1"
	exit -1
fi

if [ ! -d $SRC_DIR ]; then
	mkdir $SRC_DIR
fi

if [ ! -d $DST_DIR ]; then
	mkdir $DST_DIR
fi

echo "Mount ${SRC} $SRC_DIR"
mount ${SRC} $SRC_DIR

if [ $? -ne 0 ]; then
	exit 1
fi

echo "Mount ${DST} $DST_DIR"
mount ${DST} $DST_DIR

if [ $? -ne 0 ]; then
	umount $SRC_DIR
	exit 2
fi

cp -afv $SRC_DIR/* $DST_DIR

echo "Umount ${SRC}1 ${DST}1"
umount $SRC_DIR
umount $DST_DIR

rmdir $SRC_DIR
rmdir $DST_DIR

